package main

import (
	"encoding/json"
	"fmt"
	"secure-comm/pkg/crypto"
)

func main() {
	// 初始化加密参数
	crypto.InitCrypto("12345678901234567890123456789012", "1234567890123456")
	
	// 测试数据
	testData := map[string]interface{}{
		"username": "admin",
		"password": "password",
	}
	
	// 加密
	encrypted, err := crypto.Encrypt(testData)
	if err != nil {
		fmt.Printf("Encryption failed: %v\n", err)
		return
	}
	
	fmt.Printf("Encrypted: %s\n", encrypted)
	
	// 解密
	var decrypted map[string]interface{}
	err = crypto.Decrypt(encrypted, &decrypted)
	if err != nil {
		fmt.Printf("Decryption failed: %v\n", err)
		return
	}
	
	fmt.Printf("Decrypted: %v\n", decrypted)
	
	// 验证数据一致性
	if testData["username"] == decrypted["username"] && testData["password"] == decrypted["password"] {
		fmt.Println("✅ Encryption/Decryption test passed!")
	} else {
		fmt.Println("❌ Encryption/Decryption test failed!")
	}
	
	// 测试用于API的格式
	fmt.Println("\n--- API Test Format ---")
	apiRequest := map[string]string{
		"encrypted": encrypted,
	}
	
	jsonData, _ := json.Marshal(apiRequest)
	fmt.Printf("API Request: %s\n", string(jsonData))
}
